package adapters;

import pessoa.ControlePessoa;
import pessoa.Pessoa;
import usuario.ControladorUsuario;

import chamados.Chamado;

import com.example.taketaxi.R;
import com.example.taketaxi.conexaoBanco.BaseDadosContract.ChamadoEntry;
import com.example.taketaxi.conexaoBanco.BaseDadosContract.PessoasEntry;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class ChamadoAdapterCliente extends SimpleCursorAdapter {
	private LayoutInflater inflater;
	private int layout = R.layout.adapter_chamados;
	Cursor cursor;
	private Pessoa usuario;
	private	ControlePessoa controle;
	
	@SuppressWarnings("deprecation")
	public ChamadoAdapterCliente(Context context, int layout, Cursor c, String[] from,	int[] to, Pessoa pessoa) {
		super(context, layout, c, from, to);
		this.inflater = LayoutInflater.from(context);
		this.cursor = c;
		this.usuario = usuario;
		controle = new ControlePessoa(context);
	}

	
	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		return inflater.inflate(layout, null);
	}
	
	@Override
	public void bindView(View convertView, Context context, Cursor c) {
		super.bindView(convertView, context, c);
		
		TextView cliente, status;
		
		cliente = (TextView)convertView.findViewById(R.id.txtcliente);
		status = (TextView)convertView.findViewById(R.id.txtstatus);
		
		
		
		cliente.setText("Taxista : " + controle.getPessoaByid(c.getLong(c.getColumnIndex(ChamadoEntry.IDTAXISTA))).getNome_razao());
		status.setText("Status: " + c.getString(c.getColumnIndex(ChamadoEntry.STATUS)));
		
		if(c.getString(c.getColumnIndex(ChamadoEntry.STATUS)).equalsIgnoreCase("Atendendo")){
			status.setTextColor(context.getResources().getColor(R.color.YELLOW));
		}else if (c.getString(c.getColumnIndex(ChamadoEntry.STATUS)).equalsIgnoreCase("Cancelado")){
			status.setTextColor(context.getResources().getColor(R.color.RED));
		}else if(c.getString(c.getColumnIndex(ChamadoEntry.STATUS)).equalsIgnoreCase("Aguardando")){
			status.setTextColor(context.getResources().getColor(R.color.GREEN));
		}
	}
}
